package com.SkiOnSofa;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class Buscador extends ListActivity {
		
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        String[] estacions = getResources().getStringArray(R.array.estacions_array);
        setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, estacions));

        ListView lv = getListView();
        lv.setTextFilterEnabled(true);

        lv.setOnItemClickListener(new OnItemClickListener() {
          public void onItemClick(AdapterView<?> parent, View view,
              int position, long id) {
        	  
        	    MyApp appState = ((MyApp)getApplicationContext());
        	    appState.setSkiStation(((TextView) view).getText()); //Better than a global variable
        	  	Intent intent = new Intent();
        	  	intent.setClass(Buscador.this, Mapa.class); 
        	  	startActivity(intent);        	  	
            // Provisional: Quan es pulsa es mostra un toast, cambiar per acces a mapa
        	//  	Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
        	//  			Toast.LENGTH_SHORT).show();
          }
        });       
    }
}
